<template>
  <div class="listWapper">
    <customDetailsTopbar title="固废管理" flag @back="back" />
    <div id="customScroolBox" class="listInner px-1">
      <div class="d-flex mt-2 w-100">
        <custom-radio-tag1 class="mb-1 w-100" :list="tagList" :value="checkedValue" is-scroll @change="tagChange" />
      </div>
      <customSearch ref="customSearch" placeholder="请输入企业名称" title="固废列表" :total="total" :is-super-search="true" @search="handleSearch" @superSearch="openSuperSearch" />
      <div v-if="tableList.length > 0" class="common_list">
        <div v-for="(item,index) in tableList" :key="index" class="list_item" @click="goDetail(item)">
          <div class="content_area">
            <div class="number_order">{{ index + 1 }}</div>
            <div class="right_content">
              <div class="content_title" style="max-width: 100%">
                {{ item.companyName }}
              </div>
              <ul class="des-list">
                <li v-for="(des,ind) in desList" :key="des.value" class="des">
                  <i :class="'iconfont c-text-color' + ((ind % 7) + 1)" v-html="des.icon" />
                  <div class="label">{{ des.label }}：</div>
                  <div class="value">{{ item[des.value] !== '' && item[des.value]!==undefined?item[des.value]:'/' }}</div>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
      <customLoadmore ref="customLoadmore" :page-num="form.pageNum" :pages="pages" @load="handlePages" />
    </div>
    <van-popup v-model="superSearch" position="right" :style="{ width: '90%', height: '100%' }" lock-scroll close-on-popstate closeable class="custom-van-pop">
      <div class="pop-vertical-flex">
        <div class="pop-content">
          <template v-if="checkedTag === '产废台账'">
            <custom-timer type="date" title="产生时间" :start.sync="form.startTime" :end.sync="form.endTime" :is-interval="true" :picker-title="'请选择产生时间'" />
          </template>
          <template v-else-if="checkedTag === '贮存台账'">
            <custom-timer type="date" title="贮存时间" :start.sync="form.startTime" :end.sync="form.endTime" :is-interval="true" :picker-title="'请选择贮存时间'" />
          </template>
          <template v-else-if="checkedTag === '出库台账'">
            <custom-timer type="date" title="出库时间" :start.sync="form.startTime" :end.sync="form.endTime" :is-interval="true" :picker-title="'请选择出库时间'" />
          </template>
        </div>
        <div class="pop-bottom">
          <van-button type="default" @click="resetSuperSearch">清空</van-button>
          <van-button type="info" @click="handleSuperSearch">确认</van-button>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import commonList from '@/assets/mixin/commonList'
import { WasteStandingList } from '@/api/environment'

export default {
  mixins: [commonList],
  data() {
    return {
      total: 10,
      pages: 1,
      form: {
        // companyIds: '',
        listType: 1, // 1=转运台账，2=贮存台账，3=处置台账
        startTime: '',
        endTime: '',
        pageNum: 1,
        pageSize: 10,
        companyIds: -1
      },
      tagList: [
        { label: '产废台账', value: 1 },
        { label: '贮存台账', value: 2 },
        { label: '出库台账', value: 3 }
      ],
      checkedValue: 0,
      checkedTag: '产废台账',
      desListMap: {
        '产废台账': [
          { label: '固危废类别', value: 'wasteCategory', icon: '&#xe791;' },
          { label: '固危废类型', value: 'wasteType', icon: '&#xe61c;' },
          { label: '固危废代码', value: 'wasteCode', icon: '&#xe61c;' },
          { label: '产生时间', value: 'ttime', icon: '&#xe685;' },
          { label: '产生量', value: 'tvalue', icon: '&#xe61c;' },
          { label: '计量单位', value: 'meterUnit', icon: '&#xe61c;' },
          { label: '二维码序列号', value: 'serialNumber', icon: '&#xe61c;' },
          { label: '二维码场所', value: 'place', icon: '&#xe61c;' },
          { label: '固危废名称（俗称）', value: 'wasteName', icon: '&#xe61c;' },
          { label: '污染特性', value: 'pollutingProperty', icon: '&#xe61c;' },
          { label: '经办人', value: 'handleUser', icon: '&#xe61c;' },
          { label: '计划去向', value: 'planToGo', icon: '&#xe61c;' },
          { label: '联系方式', value: 'handlePhone', icon: '&#xe61c;' },
          { label: '转运编号', value: 'transportCode', icon: '&#xe61c;' }
        ],
        '贮存台账': [
          { label: '固危废类别', value: 'wasteCategory', icon: '&#xe791;' },
          { label: '固危废类型', value: 'wasteType', icon: '&#xe791;' },
          { label: '固危废代码', value: 'wasteCode', icon: '&#xe61c;' },
          { label: '贮存量', value: 'tvalue', icon: '&#xe61c;' },
          { label: '计量单位', value: 'meterUnit', icon: '&#xe61c;' },
          { label: '二维码序列号', value: 'serialNumber', icon: '&#xe61c;' },
          { label: '二维码场所', value: 'place', icon: '&#xe61c;' },
          { label: '固危废名称（俗称）', value: 'wasteName', icon: '&#xe61c;' },
          { label: '经办人', value: 'handleUser', icon: '&#xe61c;' },
          { label: '联系方式', value: 'handlePhone', icon: '&#xe61c;' },
          { label: '贮存车间', value: 'storagePlace', icon: '&#xe62e;' },
          { label: '贮存时间', value: 'ttime', icon: '&#xe685;' }
        ],
        '出库台账': [
          { label: '固危废类别', value: 'wasteCategory', icon: '&#xe791;' },
          { label: '固危废类型', value: 'wasteType', icon: '&#xe791;' },
          { label: '二维码序列号', value: 'serialNumber', icon: '&#xe61c;' },
          { label: '固危废代码', value: 'wasteCode', icon: '&#xe61c;' },
          { label: '二维码场所', value: 'place', icon: '&#xe61c;' },
          { label: '固危废名称（俗称）', value: 'wasteName', icon: '&#xe61c;' },
          { label: '经办人', value: 'handleUser', icon: '&#xe61c;' },
          { label: '联系方式', value: 'handlePhone', icon: '&#xe61c;' },
          { label: '出库量', value: 'tvalue', icon: '&#xe61c;' },
          { label: '计量单位', value: 'meterUnit', icon: '&#xe61c;' },
          { label: '出库时间', value: 'ttime', icon: '&#xe685;' }
        ]
      },
      current: '',
      desList: [],
      tableList: []
    }
  },
  mounted() {
    const { current, tag } = this.$route.query
    this.current = current || ''
    this.checkedTag = tag || '产废台账'
    this.tagList.find((v, index) => {
      if (v.label === this.checkedTag) {
        this.form.listType = v.value
        this.checkedValue = index
      }
    })
    this.desList = this.desListMap[this.checkedTag]
    this.WasteStandingList()
  },
  methods: {
    // 退回工作台
    back() {
      this.$router.push({
        path: '/staging/environBusiness',
        query: { current: this.current }
      })
    },
    // 获取固废列表
    async WasteStandingList() {
      this.$refs.customLoadmore.loadStatus = true
      // this.layout.showLoading()
      const { status, data } = await WasteStandingList(this.form)
      if (status === 0 && data) {
        this.tableList = this.tableList.concat(data.list)
        this.total = data.total
        this.pages = data.pages
      }
      this.$refs.customLoadmore.loadStatus = false
      // this.layout.hideLoading()
    },
    // 跳转详情
    goDetail(item) {
      this.$router.push({
        path: '/staging/solidWasteDetail',
        query: { current: this.current, tag: this.checkedTag, companyIds: item.companyId, ...item }
      })
    },
    // tab 切换
    tagChange(val) {
      this.form.listType = val.item.value
      this.checkedTag = val.item.label
      this.resetSuperSearch()
      this.desList = this.desListMap[this.checkedTag]
      this.tableList = []
      this.WasteStandingList()
    },
    // 分页
    handlePages(value) {
      this.form.pageNum = value
      this.WasteStandingList()
    },
    // 企业名称查询
    handleSearch(value) {
      this.form.companyName = value
      this.form.pageNum = 1
      this.tableList = []
      this.WasteStandingList()
    },
    resetSuperSearch() {
      const listType = this.form.listType
      Object.keys(this.form).forEach(key => { this.form[key] = '' })
      this.$refs.customSearch.restore()
      this.form.pageNum = 1
      this.form.pageSize = 10
      this.form.companyIds = -1
      this.form.listType = listType
    },
    handleSuperSearch() {
      this.superSearch = false
      this.form.pageNum = 1
      this.tableList = []
      this.WasteStandingList()
    }
  }
}
</script>

<style lang="scss" scoped>
.checkbox-title {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 30px;
}

.right_content{
  .des-list{
    display: flex;
    flex-wrap: wrap;
    .des{
      width: 100%;
    }
  }
}
</style>
